using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NTTHAO.CommonWeb;
using NTTHAO.Common.BL;
using NTTHAO.Web.BL.CommonPage;

public partial class admin_webparts_Common_SiteInput : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        btnSave.Text = btnSave2.Text = LanguageUtility.GetLanguageText("SAVE", Session);
        try
        {
            if (!IsPostBack)
            {
                Language lang = new Language();
                DataSet ds = lang.GetAll();
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    cmbDefaultLaguage.DataSource = ds.Tables[0];
                    cmbDefaultLaguage.DataTextField = Language.NAME__COLUMN_NAME;
                    cmbDefaultLaguage.DataValueField = Language.ID__COLUMN_NAME;
                    //cmbDefaultLaguage.SelectedValue = LanguageUtility.GetLanguageID(Request, Session).ToString();
                    cmbDefaultLaguage.DataBind();
                }

                CommonSite site = WebGlobal.GetSite(Session);
                if (site == null)
                {
                    Response.Redirect("?");
                    return;
                }

                txtSiteID.Text = site.SiteID;
                txtSiteName.Text = site.SiteName;
                txtDomain.Text = site.SiteDomain;
                cmbDefaultLaguage.SelectedValue = site.DefaultLanguage.ToString();
                txtContentType.Text = site.ContentType;
                txtTitle.Text = site.Title;
                txtKeywords.Text = site.Keywords;
                txtDescription.Text = site.Description;
                txtAuthor.Text = site.Author;
                txtCopyright.Text = site.Copyright;
                txtGenerator.Text = site.Generator;
                txtShortcutIcon.Text = site.ShortcutIcon;
            }
        }
        catch (Exception) { }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        if ("siteedit".Equals(Request.QueryString["type"], StringComparison.OrdinalIgnoreCase))
        {
            CommonSite site = WebGlobal.GetSite(Session);

            site.SiteID = txtSiteID.Text;
            site.SiteName = txtSiteName.Text;
            site.SiteDomain = txtDomain.Text;
            site.DefaultLanguage = Int32.Parse(cmbDefaultLaguage.SelectedValue);
            site.ContentType = txtContentType.Text;
            site.Title = txtTitle.Text;
            site.Keywords = txtKeywords.Text;
            site.Description = txtDescription.Text;
            site.Author = txtAuthor.Text;
            site.Copyright = txtCopyright.Text;
            site.Generator = txtGenerator.Text;
            site.ShortcutIcon = txtShortcutIcon.Text;

            site.Update();

            Session.Remove(Constant.SITE_SESSION);
            Session.Add(Constant.SITE_SESSION, site);

            Response.Redirect("?");
        }
    }
}
